//
//  PingAction.m
//  iOSLaboratory
//
//  Created by yangshansi on 2017/4/20.
//  Copyright © 2017年 WiLL. All rights reserved.
//

#import "OnePingAction.h"

#import "SimplePing.h"

#import "OneIcmpPingAction.h"
#import "OneHttpPingAction.h"



@interface OnePingAction ()


@end




@implementation OnePingAction


/******************************************************************************/
/**** Static Method                                                        ****/
/******************************************************************************/
#pragma mark - Static Method

+ (instancetype)onePingActionWithMethod:(PingMethod)pingMethod
                         sequenceNumber:(NSInteger)sequenceNumber
                                   host:(NSString *)hostName
                                timeout:(NSInteger)timeout
                                   data:(NSData *)data
{
    if (pingMethod == PingMethodICMP)
    {
        return [[OneIcmpPingAction alloc] initWithHost:hostName
                                        sequenceNumber:sequenceNumber
                                               timeout:timeout
                                                  data:nil];
    }
    else if (pingMethod == PingMethodHTTP)
    {
        return [[OneHttpPingAction alloc] initWithHost:hostName
                                        sequenceNumber:sequenceNumber
                                               timeout:timeout
                                                  data:data];
    }
    
    return nil;
}




/******************************************************************************/
/**** Customized Method                                                    ****/
/******************************************************************************/
#pragma mark - Customized Method

- (BOOL)doOnePing
{
    // do nothing
    return NO;
}






/******************************************************************************/
/**** Lifecycle Method                                                     ****/
/******************************************************************************/
#pragma mark - Lifecycle Method

- (instancetype)initWithHost:(NSString *)hostName
              sequenceNumber:(NSInteger)sequenceNumber
                     timeout:(NSInteger)timeout
                        data:(NSData *)data
{
    self = [super init];
    if (self) {
        self->_hostName = hostName;
        self->_timeout  = timeout;
        
        self->_ip = nil;

        self->_sendTime = 0;
        self->_recvTime = 0;
        self->_interval = 0;
        
        self->_sequenceNumber = sequenceNumber;
        self->_data = data;
        self->_packetSize = 0;
    }
    return self;
}


@end
